$(function() {


    getartoken()

    function getartoken() {
        $.ajax({
            method: 'GET',
            url: '/api/articles/1/comments',

            success: function(res) {

                console.log(res);

                renderpinlun(res)

            }
        })

        function renderpinlun(res) {
            let htmlStr = template('html-pinglun', res)
            $('#pl-content').html(htmlStr)
        }

    }

    puttoken()
        // 发表评论的模块
    function puttoken() {

        $('#comment-form').on('submit', function(e) {
            // 1. 阻止表单的默认提交行为
            e.preventDefault()
            let data = {
                uname: $('[name=uname]').val(),
                content: $('[name=content]').val()
            }
            console.log(data);
            $.ajax({
                method: 'POST',
                url: '/api/articles/1/comments',
                data: data,
                success: function(res) {

                    console.log(res);

                    getartoken()

                    $('#comment-form')[0].reset()
                }
            })


        })

    }



})